{include file="header" title="$title" /}
    <div class="page-title i-card-main">
        <i class="iconfont icon-page"></i>
        <span>EDIT SETTINGS</span>
    </div>
    <div class="i-card-main">
        <div class="row" id="challenges" style="padding: 20px;">
            <div class="col-lg-12">
                <form>
                    <div class="form-row">

                        <div class="col-md-2 mb-3">
                            <label>站点标题</label>
                            <input type="text" class="form-control" id="title" placeholder="输入标题" required>
                        </div>
                        <div class="col-md-5 mb-3">
                            <label>站点描述</label>
                            <input type="text" class="form-control" id="desc" placeholder="站点描述" required>
                        </div>
                        <div class="col-md-5 mb-3">
                            <label>站点关键字</label>
                            <input type="text" class="form-control" id="keywords" placeholder="站点关键字" required>
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="col-md-1 mb-3">
                            <label>初始金币</label>
                            <input type="text" class="form-control" id="coin" placeholder="100" value="100" required>
                        </div>
                        <div class="col-md-1 mb-3">
                            <label>签到金币</label>
                            <input type="text" class="form-control" id="money" placeholder="10" value="10" required>
                        </div>
                        <div class="col-md-2 mb-3">
                            <label>注册状态</label>
                            <select class="custom-select" id="state">
                                <option>Hidden</option>
                                <option>Display</option>
                            </select>
                        </div>
                        <div class="col-md-2 mb-3">
                            <label>验证邮箱</label>
                            <select class="custom-select" id="verify">
                                <option>False</option>
                                <option>Ture</option>
                            </select>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label>统计ID</label>
                            <input type="text" class="form-control" id="stats" placeholder="0" required>
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="col-md-4 mb-3">
                            <label>发信服务器</label>
                            <input type="text" class="form-control" id="smtp">
                        </div>
                        <div class="col-md-4 mb-3">
                            <label>发信邮箱</label>
                            <input type="text" class="form-control" id="smtpName">
                        </div>
                        <div class="col-md-4 mb-3">
                            <label>发信密码</label>
                            <input type="password" class="form-control" id="smtpPass">
                        </div>
                    </div>
                    <button class="btn btn-primary" type="submit">Submit form</button>
                </form>
            </div>
        </div>
    </div>  
    {include file="footer" /}
</div>
<script>
$('.loading').show();
$('.i-card-main').eq(1).hide();
$(document).ready(function(){
    $.get("/api/v1/getSettingsInfo",function(res){
        if(res.code != 200 ){
            layer.msg(res.msg);
            return;
        }

        $("#title").val(res.data.title);
        $("#desc").val(res.data.desc);
        $("#keywords").val(res.data.keywords);
        $("#state option").each(function(){
            if($(this).text() == res.data.state){
                $(this).attr("selected",true);
            }
        });
        $("#verify option").each(function(){
            if($(this).text() == res.data.verify){
                $(this).attr("selected",true);
            }
        });
        $("#stats").val(res.data.stats);
        $("#smtp").val(res.data.smtp);
        $("#smtpName").val(res.data.smtp_name);
        $("#smtpPass").val(res.data.smtp_pass);
        $("#css").val(res.data.css);
        setTimeout(function(){
            $('.loading').hide();
            $('.i-card-main').eq(1).show();
        },500);
    });
});

$('.btn-primary').click(function(){
    const title = $("#title").val();
    const desc = $("#desc").val();
    const keywords = $("#keywords").val();
    const state = $("#state").val();
    const verify = $("#verify").val();
    const stats = $("#stats").val();
    const smtp = $("#smtp").val();
    const smtpName = $("#smtpName").val();
    const smtpPass = $("#smtpPass").val();
    const css = $("#css").val();
    $.post("/api/v1/editSettings",{
        title:title,
        desc:desc,
        keywords:keywords,
        state:state,
        verify:verify,
        stats:stats,
        smtp:smtp,
        smtp_name:smtpName,
        smtp_pass:smtpPass,
        css:css
    },function(res){
        if(res.code != 200 ){
            layer.msg(res.msg);
            return;
        }
        layer.msg(res.msg);
        setTimeout(function(){
            window.location.reload();
        },500);
    });
    return false;
});
</script>
 </body></html>